import express from 'express';
import * as serviceController from './service.controller';
import { fileInterceptor, fileProcessor } from './service.middleware';
import { validateLoginData, authGuard, userGuard } from '../auth/auth.middleware';

const router = express.Router();

/**
 * 获取内容
 */
router.get('/service', userGuard, serviceController.index);

/**
 * 获取内容(按 ID)
 */
router.get('/service/:postId', userGuard, serviceController.serviceDetail);

/**
 * 按关键字查询（模糊查询）
 */
router.get('/getServiceByKey', serviceController.selectByKey);

/**
 * 创建内容
 */
router.post('/service', authGuard, serviceController.store);

/**
 * 更新内容
 */
router.patch('/service/:postId', serviceController.update);

/**
 * 删除内容
 */
router.post('/serviceDestroy', authGuard, serviceController.destroy);

/**
 * 修改状态
 */
router.patch('/service', serviceController.status);

/**
 * 上传文件
 */
router.post('/serviceFiles', fileInterceptor, fileProcessor, serviceController.uploads);

/**
 * 文件服务
 */
router.get('/serviceFiles/:fileId/serve', serviceController.serve);

/**
 * 获取文件 ID
 */
router.post('/getServiceFilesId', serviceController.getFileName)

/**
 * 导出路由
 */
export default router;
